# Maintainer: Carlos Antunes <cmantunes@gmail.com>
# Contributed by: nanodude

_realname=binutils
_target=arm-none-eabi

pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_target}-${_realname}")
pkgver=2.24
pkgrel=1
pkgdesc="GNU Tools for ARM Embedded Processors - Binutils (mingw-w64)"
arch=('any')
url="https://www.gnu.org/software/binutils/"
license=('GPL')
groups=("${MINGW_PACKAGE_PREFIX}-${_target}-toolchain")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
options=('staticlibs')
source=("https://mirrors.kernel.org/sources.redhat.com/${_realname}/releases/${_realname}-${pkgver}.tar.bz2")
sha256sums=('e5e8c5be9664e7f7f96e0d09919110ab5ad597794f5b1809871177a0f0f14137')

build() {
  if check_option "debug" "y"; then
    CFLAGS+=" -g -O0"
  fi
  cd $srcdir
  rm -rf build-${MINGW_CHOST}
  mkdir -p build-${MINGW_CHOST} && cd build-${MINGW_CHOST}
  ../${_realname}-${pkgver}/configure \
    --build="${MINGW_CHOST}" \
    --host="${MINGW_CHOST}" \
    --target="${_target}" \
    --prefix="${MINGW_PREFIX}" \
    --disable-werror \
    --disable-lto \
    --with-sysroot="${MINGW_PREFIX}" \
    --disable-nls \
    --disable-rpath \
    --enable-multilib \
    --enable-interwork
  make
}

package() {
  cd ${srcdir}/build-${MINGW_CHOST}
  make DESTDIR=${pkgdir} install

  # Remove unwanted files
  rm -rf ${pkgdir}${MINGW_PREFIX}/share/info
}
